<?php

include('../src/imarty.php');
include('../src/lib/class.smarttemplate.php');
$file_name = "cache.txt";
$file = fopen($file_name, 'r');
$number = fgets($file);
$final_no = $number + 1;
fclose($file);
$file = fopen($file_name, 'w');
fwrite($file, $final_no);
$background_number = rand(1,9);
$size = getimagesize('resource/image/image'.$background_number.'.png');
$size2 = getimagesize('resource/image/fade.png');

$y = 133;
$i = 0;
$a = 255;
while($i < 8){
$numbers[] = array('color'=> colorlib::rgb2hex(array($a-$i*30, $a-$i*30, $a-$i*30)),
					'y' => $y - (16*$i),
					'final_no' => $final_no - $i);
++$i;
}


$tpl = new SmartTemplate('tpl/sig.tpl');
$tpl->template_dir = '';
$tpl->temp_dir = 'tpl/tpl_c/';
$tpl->cache_dir = 'tpl/tpl_c/';

$tpl->assign('back', $background_number);
$tpl->assign('w', $size[0]);
$tpl->assign('h', $size[1]);
$tpl->assign('fadew', $size2[0]);
$tpl->assign('fadeh', $size2[1]);
$tpl->assign('numbers', $numbers);
ob_start();
$tpl->output();
$xml = ob_get_contents();
ob_end_clean();
//echo $xml;

$imarty = new imarty($xml, true);
$imarty->render();
$imarty->output_image('png');

?>